<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>对象</title>
		<script>
			 function f1(){
				 //{}表示一个对象
				 //key:value 表示一对属性
				 //key通常是字符串
				 //value可以是任意类型数据
				 var student = {
					 "name":"张三",
					 "age": 20,
					 "work": function(){alert('daydayup!')}
				 }
				 //使用对象
				 alert(student.name)
				 alert(student.age)
				 student.work();
			 }
			 //Date() RegExp() Object()
			 function f2(){
				 var teacher = new Object();
				 //追加属性和值
				 teacher.name = "李四"
				 teacher.age = 30
				 teacher.work = function(){
					 alert("gogogo!")
				 }
				 //使用对象
				 alert(teacher.name)
				 alert(teacher.age)
				 teacher.work();
			 }
			 //自定义构造器
			 //定义构造函数
			 function Programmer(name,age,work){
				 //this.指代当前对象
				 this.name = name;
				 this.age = age;
				 this.work = work;
			 }
			 //使用构造方法创建对象
			 function f3(){
				 var p = new Programmer("王五",25,function(){
					 alert('德玛西亚！');
				 });
				 //使用对象
				 alert(p.name)
				 alert(p.age)
				 p.work();
			 }
			 
			 
		</script>
	</head>
	<body>
		 <input type="button" value="直接量" onclick="f1()"/>
		 <input type="button" value="预制构造器" onclick="f2()"/>
		 <input type="button" value="自定义构造器" onclick="f3()"/>
	</body>
	 
</html>